ID
Type
property
Summary
Reports the unique ID number assigned to an object.
Syntax
set the ID of {image | stack} to <number>
get the [{ long | abbreviated | short }] ID of <object>
Description
Use an object's ID property to refer to the object in an unambiguous way.
A stack's ID is equal to the ID that will be assigned to the next object created within that stack, so the stack ID is subject to change. You can set the ID of a stack, but only to a greater number than its current ID.
You can set the ID of an image. Be careful not to set an image ID to a number that's the ID of another object in the same stack : since LiveCode uses IDs to keep track of objects, a conflict may prevent LiveCode from being able to access one or both objects. The following ID numbers are reserved and should not be used for image IDs:
- 1-100: reserved for built-in cursors
- 101-135: reserved for built-in brush shapes
- 236-300: reserved for built-in patterns
- 301-1000: reserved for built-in icons
- 101,000-103,000: reserved
- 200,000-299,999: reserved for application use
For all objects, the ID is guaranteed to be unique within a stack. IDs are not reused if the object is deleted.
An object that is created by copying and pasting, or with the copy command, is assigned a new ID. If you cut an object and paste it into the same stack, it retains its original ID.
The short ID of an object is its ID number. If you don't specify a modifier for the ID property, you get the short ID form.
The abbreviated ID of an object is the object's type, followed by "id", followed by the object's short ID. For example, if a button's short ID is "27", its abbreviated ID is "button id 27".
The long id of an object includes information about its owner (and about the owner of that object, and so forth). For example, suppose a stack named "My Stack" contains a card whose ID is 11. This card has a group whose ID is 28, which in turn contains a button whose ID is 34. The card also has a card field whose ID is 46. If "My Stack" is a main stack and it's in a file whose path is "/Drive/Folder/Stack. rev", the long IDs of these objects look like this:
- The stack: stack "/Drive/Folder/Stack. rev"
- The group: group id 28 of card ID 11 of stack "/Drive/Folder/Stack. rev"
- The card: card id 11 of stack "/Drive/Folder/Stack. rev"
- The grouped button: button id 34 of group id 28 of card id 11 of stack "/Drive/Folder/Stack. rev"
- The card field: field id 46 of card id 11 of stack "/Drive/Folder/Stack. rev" If the stack is a substack, its ID is included in the long name of each of its objects, before the path of the main stack.
The long ID of a group includes the ID of the current card. If the group does not appear on the current card, requesting its ID causes an execution error. If you need to get the ID of a group, use the "background" terminology instead.
The long ID of a background includes the ID of the current card, if the background appears on the current card. If not, the long ID of the background includes the ID of the first card the background appears on.
If an object's name is empty, getting its name yields its ID property instead.
If a stack was originally created with HyperCard and then imported into LiveCode, the ID of each control in the stack is guaranteed unique only within its domain. (You can check a stack's HCStack property to determine whether it began life in HyperCard. )
If a stack's HCAddressing property is set to true, the long or abbreviated ID of a control in that stack begins with the word "background" if the control is part of a group, and with the word "card" if not.
Examples
send mouseUp to button ID 2214
set the ID of image "Custom Cursor" to 2314
put the long ID of this card into savedID
Related
command: copy, group, libURLSetLogField, push
glossary: object, card control, file path, property, control, command, image, execution error, main stack, card, current card, background, HyperCard, domain
keyword: abbreviated, file, button, long, integer
property: name, HCAddressing, owner, groupIDs, HCStack, altID, cardIDs
Compatibility and Support
Introduced
LiveCode 1.0
OS
mac
windows
linux
ios
android
Platforms
desktop
server
mobile